<template>
  <div class="common-layout h-screen">
    <el-container class="h-screen">
      <el-header class="flex justify-between items-center">
        <p class="text-gray-700 flex items-center">
          <img :src="common.logo" alt="Admin" style="height: 20px" />
          <span class="ml-4">后台管理系统</span>
        </p>
        <div class="common-user flex items-center">
          <div
            class="common-user__header flex bg-gray-100 rounded-full p-2 justify-center items-center"
          >
            <svg class="icon" aria-hidden="true" width="20" height="20">
              <use :xlink:href="`#icon-user`"></use>
            </svg>
          </div>
          <el-dropdown
            class="ml-3"
            :hide-on-click="false"
            @command="handleCommand"
          >
            <div class="el-dropdown-link flex">
              <span class="mr-1">{{ userName }}</span>
              <el-icon><caret-bottom /></el-icon>
            </div>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item command="logout">Logout</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <common-menu></common-menu>
        </el-aside>
        <div class="flex-1 p-4 bg-gray-100 box-border">
          <div class="h-full">
            <router-view></router-view>
          </div>
        </div>
      </el-container>
    </el-container>
  </div>
  <upload-progress></upload-progress>
</template>

<script lang="ts" setup>
  import { CaretBottom } from '@element-plus/icons-vue';
  // import { logout } from '@/http/login';
  import { clearAuthToken, clearPermissions } from '@/utils/auth';
  import { common } from '@/model/images/common';

  const userName = localStorage.getItem('name');

  const handleCommand = async (command: string | number | object) => {
    if (command === 'logout') {
      // await logout();
      clearPermissions();
      clearAuthToken();
    }
  };
</script>

<style lang="scss" scoped></style>
